<?php
require_once("xforms/Input.php");

class XForms_textarea extends XForms_input {
  protected $tpl = '<div class="xforms_textarea {renderClass}" >{renderHelp} {renderRequired} {renderLabel} <br /><textarea rows="4" cols="50" {renderId} {renderValue} {renderReadOnly} >  </textarea> <br /> <div class="xforms_validationmessage xforms_nonvisible"></div> {renderHint} </div>';
  protected $script = '.append(new XForms_textarea({renderJson}))';
  
  function renderClass(){
  $cssClass="";
  $binding = $this->getBinding();
  if($binding && $binding->getAttribute("relevant")) {
	$xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("relevant")){
	  case true: break;
      case false: $cssClass=$cssClass . " xforms_nonvisible";break;
      default:
    }
	
  }

  return $cssClass;
  }
  
  function renderReadOnly(){
  $readonly="";
  $binding = $this->getBinding();
  if($binding) {
	$xBinding = $this->getXElement($binding);
    switch($xBinding->evalAttribute("readonly")) {	  
      case true: $readonly= 'disabled = "disabled"'; break;
      case false: break;
      default:
    }
  }
  return $readonly;
  }

  function renderRequired(){
   $binding = $this->getBinding();
   $required="";
   if($binding){
	$xBinding = $this->getXElement($binding);
	if($xBinding->evalAttribute("required"))
     $required =  $required . '<b style="color:red"> * </b>';
  return $required;
   }
  }
  function renderLabel(){
 	return $this->renderChildNodes(array("xforms:label"));

  }
  function renderHelp(){
    return $this->renderChildNodes(array("xforms:help"));
  }
  function renderHint(){
    return $this->renderChildNodes(array("xforms:hint"));
  }
  function renderValue(){
    return htmlentities($this->getValue(), ENT_QUOTES, 'utf-8');
  }
  }
